<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>订单配置信息</title>
</head>
<script src="../static/vue.min.js"></script>
<script src="../static/global.js"></script>
<script src="../static/jquery-1.8.0.js"></script>
<script src="../elements/element.js"></script>
<link rel="stylesheet" href="../elements/element.css">
<script src="../static/axios.min.js"></script>
<body>

<!--表格渲染-->
<table class="layui-hide" id="demo" lay-filter="test"></table>
<!--侧边栏显示信息-->
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
</script>

<!--订单配置的修改信息-->


<div id="App">
    <div style="margin-top: 20px;margin-left: 40px;display: none" id="setting_DIV_up">
        <el-form ref="form" :model="form" label-width="190px">  <!-- 隐藏主键ID-->
            <el-input v-model="form.id"  style="display: none" ></el-input>
            <el-form-item label="秒杀订单超时(分)">
                <el-input-number v-model="form.flash_order_overtime" :min="1" :max="60" label="描述文字"></el-input-number>
            </el-form-item>
            <el-form-item label="正常订单超时(分)">
                <el-input-number v-model="form.normal_order_overtime" :min="1" :max="60" label="描述文字"></el-input-number>
            </el-form-item>
            <el-form-item label="自动收货(天)">
                <el-input-number v-model="form.confirm_overtime" :min="1" :max="15" label="描述文字"></el-input-number>
            </el-form-item>
            <el-form-item label="自动交易完成不退(天)">
                <el-input-number v-model="form.finish_overtime" :min="1" :max="15" label="描述文字"></el-input-number>
            </el-form-item>
            <el-form-item label="自动好评(天)">
                <el-input-number v-model="form.comment_overtime" :min="1" :max="15" label="描述文字"></el-input-number>
            </el-form-item>
            <el-form-item label="会员等级">
            <el-radio v-model="form.member_level" :label="0">不限会员等级</el-radio>
            <el-radio v-model="form.member_level" :label="1">对应会员</el-radio>
            </el-form-item>
            <el-form-item>
                <el-button :plain="true" type="primary" @click="onSubmit">立即创建</el-button>
                <el-button>取消</el-button>
            </el-form-item>
        </el-form>
    </div>
</div>


<script>
    let vue = new Vue({
        el: "#App",
        data: {
            form: {
                id:'',
                flash_order_overtime: '',
                normal_order_overtime: '',
                confirm_overtime: '',
                finish_overtime: '',
                comment_overtime: '',
                member_level:''
            }
        },
        methods: {
            //修改
            onSubmit() {
                console.log(this.form);
                axios({
                    method:"put",
                    url:glodate.serverZuul + "order_setting/up_admin_order_setting_All",
                    data:this.form
                })
                .then(res=>{
                    console.log(res.data.code);
                    if(res.data.code === 200){
                        console.log(res.data.code === 200);
                        this.$notify({
                            title: '成功',
                            message: '这是一条修改成功的提示',
                            type: 'success',
                            duration:3000
                        });
                    }else{
                        this.$notify({
                            title: res.data.msg,
                            message: '这是一条修改失败的提示消息',
                            type: 'error',
                            duration:3000
                        });
                    }
                })
            },
            find_admin_Setting_Dan(id) {
                axios.get(glodate.serverZuul + "order_setting/find_admin_Setting_Dan/" + id,
                ).then(res => {
                    console.log(res);
                    this.form = res.data
                    console.log(this.form);
                })
            }
        },
    })


    layui.use(['form', 'layer', 'table', 'laydate'], function () {
        let $ = layui.$;
        let layer = layui.layer;
        let form = layui.form;
        let laydate = layui.laydate;
        let table = layui.table;

        table.render({
            elem: '#demo',
            url: glodate.serverZuul + 'order_setting/find_admin_order_setting_All', //数据接口
            toolbar: '#toolbarDemo', //开启工具栏
            page: true,//开启分页
            cols: [[
                {type: 'checkbox', fixed: 'left'},
                {field: 'flash_order_overtime', title: '秒杀关闭事件(分)'},
                {field: 'normal_order_overtime', title: '正常订单超时(分)'},
                {field: 'confirm_overtime', title: '自动收货事件(天)'},
                {field: 'finish_overtime', title: '自动完成交易(天)不退货'},
                {field: 'comment_overtime', title: '自动好评(天)'},
                {
                    field: 'member_level', title: '会员等级', templet:
                        function (d) {
                            if (d.member_level == 0) {
                                return '<span class="layui-badge-rim">通用</span>'
                            } else {
                                return '<span class="layui-badge layui-bg-orange">对应会员等级</span>'
                            }
                        }
                },
                {fixed: 'right', align: 'center', toolbar: '#barDemo'}
            ]], id: 'tableID'
        })

        //模糊查询
        $("#order_souso").on('click', function () {
            active.reload();
            return false;
        });

        active = {
            reload: function () {
                table.reload('tableID', {
                    where: {}, page: {
                        curr: 1
                    }
                })
            }
        }


        //监听行工具事件
        table.on('tool(test)', function (obj) { //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
            var data = obj.data //获得当前行数据
                , layEvent = obj.event; //获得 lay-event 对应的值
            if (layEvent === 'edit') {
                let id = data.id;
                vue.find_admin_Setting_Dan(id);
                // form.val('setting_up_form',data);
                layer.open({
                    type: 1,
                    skin: 'demo-class',
                    title: "修改",
                    area: ['700px', '600px'],
                    anim: 5,
                    fixed: false,
                    content: $("#setting_DIV_up"), //这里content是一个普通的String
                    btn: ['关闭'],
                    yes: function (index, layero) {
                        // 重置清空
                        layer.close(index);
                        location.reload();
                    }
                });
                return false;
            }
        });

        form.on('submit(setting_up_btn)', function () {
            let datas = form.val('setting_up_form');
            console.log(datas);
            $.ajax({
                url: glodate.serverZuul + "order_setting/up_admin_order_setting_All",
                type: "put",
                data: datas,
                dataType: "json",
                success: function (res) {
                    console.log(res);
                    if (res.code == 200) {
                        layer.msg("修改成功", {icon: 6});
                    } else {
                        layer.msg(res.msg, {icon: 5});
                    }
                    setTimeout('location.reload();', 2000);
                }
            })
            formIdreset("#coupon_category_add_form");//重置表单的初始内容
            return false;
            layer.closeAll();
        })


        //提取的清除表单的方法  formId form表头的id值
        function formIdreset(formId) {
            // 重置清空
            $(formId)[0].reset();
            form.render();//必须写
        }

    });
</script>
</body>
</html>